package com.pig4cloud.pigx.wxApi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.ruralLibrary.api.entity.RecommendManageEntity;
import com.pig4cloud.pigx.wxApi.entity.BannerInfo;
import com.pig4cloud.pigx.wxApi.service.BannerService;
import com.pig4cloud.pigx.wxApi.service.RecommendManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页相关接口
 *
 * @author myg
 * @date 2023-07-19  16:06:24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/homepage")
@Tag(description = "homepage", name = "首页相关接口")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class HomePageController {
	private final BannerService bannerService;
	@Autowired
	private final RecommendManageService recommendManageService;
	@Operation(summary = "获取banner列表", description = "获取banner列表")
	@GetMapping("/getBanner")
	@Inner(false)
	public R<List<BannerInfo>> getBanner(
			@Schema(description = "【banner投放位置，不传默认返回所有】" +
					" 1 首页轮播图 2 产品页轮播图 3 帮助页轮播图")
			@RequestParam(value = "position", required = false) Integer position) {
		LambdaQueryWrapper<BannerInfo> query = new LambdaQueryWrapper<>();
		query.eq(BannerInfo::getStatus, 1);
		if (position != null) {
			query.eq(BannerInfo::getPosition, position);
		}
		List<BannerInfo> list = bannerService.list(query);
		return R.ok(list);
	}

	@Operation(summary = "获取推荐位列表", description = "获取banner列表")
	@GetMapping("/getRecommend")
	@Inner(false)
	public R<List<RecommendManageEntity>> getRecommend() {
		LambdaQueryWrapper<RecommendManageEntity> query = new LambdaQueryWrapper<>();
		query.eq(RecommendManageEntity::getState, 0);
		List<RecommendManageEntity> list = recommendManageService.list(query);
		return R.ok(list);
	}

}
